package com.smile.f213;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ComboBoxDemo {
	private JLabel label;
	public void createUI(){
		JFrame frame = new JFrame("列表框示例程序");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		String [] items = {"选项一","选项二","选项三"};
		JComboBox<?> comboBox = new JComboBox<>(items);
		comboBox.addActionListener(new ComboBoxAction());
		
		label = new JLabel();
		frame.getContentPane().add(comboBox,BorderLayout.NORTH);
		frame.getContentPane().add(label,BorderLayout.SOUTH);
		
		frame.setBounds(200, 200, 250, 120);
		frame.setVisible(true);
	}
	class ComboBoxAction implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			JComboBox<?> box = (JComboBox<?>)arg0.getSource();
			label.setText(box.getSelectedItem()+"被选择");
		}
	}
	public static void main(String[] args) {
		ComboBoxDemo example = new ComboBoxDemo();
		example.createUI();
	}
}